package it.jx.wormholes.physics;
public class Gravitation extends ExternalForce {
	private World world;
	public static double G = 6.67428e-11;
	private static double epsilon = 1e-6;

	public Gravitation(World w) {
		this.world = w;
	}

	@Override
	public Point3D value(Mass m) {
		double x = 0.0, y = 0.0, z = 0.0, c;

		for (Mass m2 : world.getMasses()) {
			if (m2 != m) {
				c = m.mass
						* G
						* m2.mass
						/ Math.pow(m.position.squareDistance(m2.position)
								+ epsilon, 1.5);

				x += c * (m2.position.x - m.position.x);
				y += c * (m2.position.y - m.position.y);
				z += c * (m2.position.z - m.position.z);
			}
		}

		return new Point3D(x, y, z);
	}

	@Override
	public boolean update(double dt) {
		return true;
	}
}
